package com.shenmazong.ware.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.MessageVo;
import com.shenmazong.ware.service.IMessageService1;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2022/7/5 17:48
 */

@Service
@Slf4j
public class IMessageService1Impl implements IMessageService1 {

    public ResultResponse handleError(MessageVo messageVo) {
        System.out.println("handleError:熔断了");
        return ResultResponse.FAILED(500);
    }

    @Override
    @HystrixCommand(
            fallbackMethod = "handleError",
            commandProperties = {
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
            })
    public ResultResponse sendMessage(MessageVo messageVo) {
        try {
            for (int index = 0; index < 10; index++) {
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return ResultResponse.SUCCESS();
    }
}
